﻿using Common;
using DLL;
using NursingDocumentInfoSystem;
using NursingFormSystem.Common;
using NursingFormSystem.Model;
using SQLDLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace NursingFormSystem.HospitalizedChildren
{
    public partial class AddHospitalizedChildren : Form
    {
        NursingFormRecord record = new NursingFormRecord();
        NursingFormSystem.NurFormsService.NursingForm formService = new NursingFormSystem.NurFormsService.NursingForm();
        Tb_User LoginUser;
        PatientInfo PatientInfo;
        string Id;
        ElectronicSignature es;
        public AddHospitalizedChildren(Tb_User loginUser, PatientInfo patientInfo)
        {
            InitializeComponent();
            this.LoginUser = loginUser;
            this.PatientInfo = patientInfo;

            es = new ElectronicSignature(LoginUser);//电签实例化

            BindControl();
            BindInfo(this.Id);
        }
        public AddHospitalizedChildren(string[] loginUser, string[] patientInfo)
        {
            InitializeComponent();
            this.LoginUser = ArrayToObject.ArrayToLoginUser(loginUser);
            this.PatientInfo = ArrayToObject.ArrayToPatientInfo(patientInfo);

            es = new ElectronicSignature(LoginUser);//电签实例化

            BindControl();
            BindInfo(this.Id);
        }

        #region 复选框勾选变化事件
        void chkFeiyonglaiy7_CheckedChanged(object sender, EventArgs e)
        {
            if (chkFeiyonglaiy7.Checked)
            {
                txtFeiYongLaiy.Visible = true;
            }
            else
            {
                txtFeiYongLaiy.Visible = false;
                txtFeiYongLaiy.Text = string.Empty;
            }
        }

        void chkShenghuohj5_CheckedChanged(object sender, EventArgs e)
        {
            if (chkShenghuohj5.Checked)
            {
                txtShenghuohj.Visible = true;
            }
            else
            {
                txtShenghuohj.Visible = false;
                txtShenghuohj.Text = string.Empty;
            }
        }

        void checkDaoGuan7_CheckedChanged(object sender, EventArgs e)
        {
            if (checkDaoGuan7.Checked)
            {
                checkDaoGuan8.Visible = true;
            }
            else
            {
                checkDaoGuan8.Visible = false;
                checkDaoGuan8.Text = string.Empty;
            }
        }

        void checkPiFu12_CheckedChanged(object sender, EventArgs e)
        {
            if (checkPiFu12.Checked)
            {
                checkPiFu13.Visible = true;
            }
            else
            {
                checkPiFu13.Visible = false;
                checkPiFu13.Text = string.Empty;
            }
        }

        void checKouChun6_CheckedChanged(object sender, EventArgs e)
        {
            if (checKouChun6.Checked)
            {
                checKouChun7.Visible = true;
            }
            else
            {
                checKouChun7.Visible = false;
                checKouChun7.Text = string.Empty;
            }
        }

        void checkKouQiang4_CheckedChanged(object sender, EventArgs e)
        {
            if (checkKouQiang4.Checked)
            {
                checkKouQiang5.Visible = true;
            }
            else
            {
                checkKouQiang5.Visible = false;
                checkKouQiang5.Text = string.Empty;
            }
        }

        void checShenZhi7_CheckedChanged(object sender, EventArgs e)
        {
            if (checShenZhi7.Checked)
            {
                checShenZhi8.Visible = true;
            }
            else
            {
                checShenZhi8.Visible = false;
                checShenZhi8.Text = string.Empty;
            }
        }

        void checkQiTa_CheckedChanged(object sender, EventArgs e)
        {
            if (checkQiTa.Checked)
            {
                checkQiTa_Text.Visible = true;
            }
            else
            {
                checkQiTa_Text.Visible = false;
                checkQiTa_Text.Text = string.Empty;
            }
        }

        void checkGuoMinShi_QiTa_CheckedChanged(object sender, EventArgs e)
        {
            if (checkGuoMinShi_QiTa.Checked)
            {
                checkGuoMinShi_QiTa_Text.Visible = true;
            }
            else
            {
                checkGuoMinShi_QiTa_Text.Visible = false;
                checkGuoMinShi_QiTa_Text.Text = string.Empty;
            }
        }

        void checkGuoMinShi_ShiWu_CheckedChanged(object sender, EventArgs e)
        {
            if (checkGuoMinShi_ShiWu.Checked)
            {
                checkGuoMinShi_ShiWu_Text.Visible = true;
            }
            else
            {
                checkGuoMinShi_ShiWu_Text.Visible = false;
                checkGuoMinShi_ShiWu_Text.Text = string.Empty;
            }
        }

        void checkGuoMinShi_YaoWu_CheckedChanged(object sender, EventArgs e)
        {
            if (checkGuoMinShi_YaoWu.Checked)
            {
                checkGuoMinShi_YaoWu_Text.Visible = true;
            }
            else
            {
                checkGuoMinShi_YaoWu_Text.Visible = false;
                checkGuoMinShi_YaoWu_Text.Text = string.Empty;
            }
        }

        void checkYuGangJieZhong_WeiAnJiHua_CheckedChanged(object sender, EventArgs e)
        {
            if (checkYuGangJieZhong_WeiAnJiHua.Checked)
            {
                checkYuGangJieZhong_Text.Visible = true;
            }
            else
            {
                checkYuGangJieZhong_Text.Visible = false;
                checkYuGangJieZhong_Text.Text = string.Empty;
            }
        }
        void checkPaiNiao9_CheckedChanged(object sender, EventArgs e)
        {
            if (checkPaiNiao9.Checked)
            {
                txtPaiNiaoVal.Visible = true;
            }
            else
            {
                txtPaiNiaoVal.Visible = false;
                txtPaiNiaoVal.Text = string.Empty;
            }
        }
        #endregion

        /// <summary>
        /// 绑定控件数据
        /// </summary>
        private void BindControl()
        {
            if (this.PatientInfo == null) return;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc = XmlUtil.GetItems();
            XmlNodeList list = xmlDoc.GetElementsByTagName("Items");
            if (list == null || list.Count == 0) { return; }
            for (int i = 0; i < list.Count; i++)
            {
                int listCount = list[i].ChildNodes.Count;
                if (listCount > 0)//判断是否有子项
                {
                    string itemsKey = list[i].Attributes["key"].Value;//<Items key="卡类型" default="">娶到Items节点中key的值
                    for (int j = 0; j < listCount; j++)
                    {
                        string itemKey = list[i].ChildNodes[j].Attributes["key"].Value;//给需要的下拉框赋值
                        if (itemsKey.Equals("民族"))
                        {
                            ddlNationals.Properties.Items.Add(itemKey);
                        }
                        if (itemsKey.Equals("与患者关系"))
                        {
                            ddlPATIENT_RELATION.Properties.Items.Add(itemKey);
                        }
                        //if (itemsKey.Equals("文化程度"))
                        //{
                        //    ddlEducation.Properties.Items.Add(itemKey);//<Item key="医保卡" value="1"/>
                        //}
                        //if (itemsKey.Equals("职业"))
                        //{
                        //    ddlJob.Properties.Items.Add(itemKey);
                        //}
                    }
                }
            }
        }

        /// <summary>
        /// 绑定读取数据
        /// </summary>
        /// <param name="id"></param>
        public void BindInfo(string id)
        {
            txtRuYuan_HuShiQianMing.EditValue = LoginUser.UserName;
            dateShiJian.DateTime = DateTime.Now;
            txtName.EditValue = PatientInfo.PATIENT_NAME;
            ddlSex.Text = PatientInfo.SEX;
            txtAge.EditValue = PatientInfo.AGE;
            txtArea.EditValue = PatientInfo.NURSE_CELL_NAME;
            txtDepartment.EditValue = PatientInfo.DEPARTMENT_NAME;
            txtBedNo.EditValue = PatientInfo.BED_NO;
            txtPatientId.EditValue = PatientInfo.PATIENT_ID;
            txtPhone.EditValue = PatientInfo.PHONE;
            txtInDate.EditValue = PatientInfo.IN_DEPARTMENT_DATE.ToString("yyyy-MM-dd HH:mm");
            txtDiagnose.EditValue = PatientInfo.DIAGNOSE;
            ddlNationals.EditValue = PatientInfo.NATIONALS;

            var ret = formService.GetNursingFormRecordOrderByTime(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.Childs, 1);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                if (string.IsNullOrEmpty(this.Id))
                    record = list[0];
                else
                    record = list.Find(p => p.Id == Convert.ToInt32(this.Id));
                this.Id = record.Id.ToString();
                var NursingFormData = record.NursingFormData;
                Child child = new Child();
                child = XmlUtil.XMLToObject<Child>(NursingFormData, Encoding.UTF8);
                txtName.EditValue = child.JiBenXinXiC.XingMing;
                if (string.IsNullOrEmpty(txtName.Text))
                    txtName.EditValue = PatientInfo.PATIENT_NAME;
                ddlSex.EditValue = child.JiBenXinXiC.XingBie;
                if (string.IsNullOrEmpty(ddlSex.Text))
                    ddlSex.Text = PatientInfo.SEX;
                txtAge.EditValue = child.JiBenXinXiC.NianLing;
                if (string.IsNullOrEmpty(txtAge.Text) || !txtAge.Text.Equals(PatientInfo.AGE))
                    txtAge.EditValue = PatientInfo.AGE;
                txtArea.EditValue = child.JiBenXinXiC.BingQu;
                if (string.IsNullOrEmpty(txtArea.Text))
                    txtArea.EditValue = PatientInfo.NURSE_CELL_NAME;
                txtDepartment.EditValue = child.JiBenXinXiC.KeShi;
                if (string.IsNullOrEmpty(txtDepartment.Text))
                    txtDepartment.EditValue = PatientInfo.DEPARTMENT_NAME;
                txtBedNo.EditValue = child.JiBenXinXiC.ChuangHao;
                if (string.IsNullOrEmpty(txtBedNo.Text))
                    txtBedNo.EditValue = PatientInfo.BED_NO;
                txtPatientId.EditValue = child.JiBenXinXiC.BingAnHao;
                if (string.IsNullOrEmpty(txtPatientId.Text))
                    txtPatientId.EditValue = PatientInfo.PATIENT_ID;
                txtInDate.EditValue = child.JiBenXinXiC.RuYuanShiJian;
                if (string.IsNullOrEmpty(txtInDate.Text))
                    txtInDate.EditValue = PatientInfo.IN_DEPARTMENT_DATE.ToString("yyyy-MM-dd HH:mm");
                ddlMode.EditValue = child.JiBenXinXiC.RuYuanFangShi;
                txtDiagnose.EditValue = child.JiBenXinXiC.RuYuanZhenDuan;
                if (string.IsNullOrEmpty(txtDiagnose.Text))
                {
                    txtDiagnose.Text = PatientInfo.DIAGNOSE;
                }
                if (string.IsNullOrEmpty(txtDiagnose.Text))
                {
                    string sql = string.Format("SELECT TOP 1 DIAGNOSE FROM dbo.V_YDHL_PATIENT(NOLOCK) WHERE PATIENT_ID = '{0}' AND VISIT_ID = '{1}'", PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID);
                    object obj = SqlHelper.ExecuteScalar(sql);
                    if (obj != DBNull.Value && obj != null && !string.IsNullOrEmpty(obj.ToString()))
                        txtDiagnose.Text = obj.ToString();
                }
                ddlNationals.EditValue = child.JiBenXinXiC.MinZu;
                txtNativePlace.EditValue = child.JiBenXinXiC.JiGuan;
                txtLinkman.EditValue = child.JiBenXinXiC.LianXiRen;
                ddlPATIENT_RELATION.EditValue = child.JiBenXinXiC.YuHuanZheGuanXi;
                txtPhone.EditValue = child.JiBenXinXiC.LianXiDianHua;
                txtTEMPERATURE.EditValue = child.JiBenXinXiC.T;
                txtPULSE.EditValue = child.JiBenXinXiC.P;
                txtBREATHING.EditValue = child.JiBenXinXiC.R;
                if (!string.IsNullOrEmpty(child.JiBenXinXiC.BP) && child.JiBenXinXiC.BP.Split('/').Length == 2)
                {
                    txtBLOOD_PRESSURE1.EditValue = child.JiBenXinXiC.BP.Split('/')[0];
                    txtBLOOD_PRESSURE2.EditValue = child.JiBenXinXiC.BP.Split('/')[1];
                }
                else
                {
                    txtBLOOD_PRESSURE1.EditValue = child.JiBenXinXiC.BP1;
                    txtBLOOD_PRESSURE2.EditValue = child.JiBenXinXiC.BP2;
                }
                txtSPO.EditValue = child.JiBenXinXiC.SPO;
                textHight.EditValue = child.JiBenXinXiC.ShenGao;
                txtWEIGHT.EditValue = child.JiBenXinXiC.TiZhong;

                if (!string.IsNullOrEmpty(child.TiZhengXinXiC.ShenZhi))
                {
                    checShenZhi1.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[0].Equals("1");
                    checShenZhi2.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[1].Equals("1");
                    checShenZhi3.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[2].Equals("1");
                    checShenZhi4.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[3].Equals("1");
                    checShenZhi5.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[4].Equals("1");
                    checShenZhi6.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[5].Equals("1");
                    checShenZhi7.Checked = child.TiZhengXinXiC.ShenZhi.Split('#')[6].Equals("1");
                }

                checShenZhi8.EditValue = child.TiZhengXinXiC.ShenZhiText;
                if (checShenZhi7.Checked) checShenZhi8.Visible = true;

                if (!string.IsNullOrEmpty(child.TiZhengXinXiC.JingShen))
                {
                    checJingShen1.Checked = child.TiZhengXinXiC.JingShen.Split('#')[0].Equals("1");
                    checJingShen2.Checked = child.TiZhengXinXiC.JingShen.Split('#')[1].Equals("1");
                    checJingShen3.Checked = child.TiZhengXinXiC.JingShen.Split('#')[2].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.TiZhengXinXiC.KouQiang))
                {
                    if (child.TiZhengXinXiC.KouQiang.Split('#').Length != 4)
                        child.TiZhengXinXiC.KouQiang = "0#0#0#0";
                    checkKouQiang1.Checked = child.TiZhengXinXiC.KouQiang.Split('#')[0].Equals("1");
                    checkKouQiang2.Checked = child.TiZhengXinXiC.KouQiang.Split('#')[1].Equals("1");
                    checkKouQiang3.Checked = child.TiZhengXinXiC.KouQiang.Split('#')[2].Equals("1");
                    checkKouQiang4.Checked = child.TiZhengXinXiC.KouQiang.Split('#')[3].Equals("1");
                }
                checkKouQiang5.Text = child.TiZhengXinXiC.KouQiangText;
                if (checkKouQiang4.Checked) checkKouQiang5.Visible = true;
                if (!string.IsNullOrEmpty(child.TiZhengXinXiC.KouChun))
                {
                    if (child.TiZhengXinXiC.KouChun.Split('#').Length != 6)
                        child.TiZhengXinXiC.KouChun = "0#0#0#0#0#0";
                    checKouChun1.Checked = child.TiZhengXinXiC.KouChun.Split('#')[0].Equals("1");
                    checKouChun2.Checked = child.TiZhengXinXiC.KouChun.Split('#')[1].Equals("1");
                    checKouChun3.Checked = child.TiZhengXinXiC.KouChun.Split('#')[2].Equals("1");
                    checKouChun4.Checked = child.TiZhengXinXiC.KouChun.Split('#')[3].Equals("1");
                    checKouChun5.Checked = child.TiZhengXinXiC.KouChun.Split('#')[4].Equals("1");
                    checKouChun6.Checked = child.TiZhengXinXiC.KouChun.Split('#')[5].Equals("1");
                }
                checKouChun7.EditValue = child.TiZhengXinXiC.KouChunText;
                if (checKouChun6.Checked) checKouChun7.Visible = true;

                if (!string.IsNullOrEmpty(child.TiZhengXinXiC.PiFu))
                {
                    checkPiFu1.Checked = child.TiZhengXinXiC.PiFu.Split('#')[0].Equals("1");
                    checkPiFu2.Checked = child.TiZhengXinXiC.PiFu.Split('#')[1].Equals("1");
                    checkPiFu3.Checked = child.TiZhengXinXiC.PiFu.Split('#')[2].Equals("1");
                    checkPiFu4.Checked = child.TiZhengXinXiC.PiFu.Split('#')[3].Equals("1");
                    checkPiFu5.Checked = child.TiZhengXinXiC.PiFu.Split('#')[4].Equals("1");
                    checkPiFu6.Checked = child.TiZhengXinXiC.PiFu.Split('#')[5].Equals("1");
                    checkPiFu7.Checked = child.TiZhengXinXiC.PiFu.Split('#')[6].Equals("1");
                    checkPiFu8.Checked = child.TiZhengXinXiC.PiFu.Split('#')[7].Equals("1");
                    checkPiFu9.Checked = child.TiZhengXinXiC.PiFu.Split('#')[8].Equals("1");
                    checkPiFu10.Checked = child.TiZhengXinXiC.PiFu.Split('#')[9].Equals("1");
                    checkPiFu11.Checked = child.TiZhengXinXiC.PiFu.Split('#')[10].Equals("1");
                    checkPiFu12.Checked = child.TiZhengXinXiC.PiFu.Split('#')[11].Equals("1");
                }
                checkPiFu13.EditValue = child.TiZhengXinXiC.PiFuText;
                if (checkPiFu12.Checked) checkPiFu13.Visible = true;

                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.YinShi_ShiYu))
                {
                    chkShiYu1.Checked = child.SheHuiPingGuC.YinShi_ShiYu.Split('#')[0].Equals("1");
                    chkShiYu2.Checked = child.SheHuiPingGuC.YinShi_ShiYu.Split('#')[1].Equals("1");
                    chkShiYu3.Checked = child.SheHuiPingGuC.YinShi_ShiYu.Split('#')[2].Equals("1");
                    chkShiYu4.Checked = child.SheHuiPingGuC.YinShi_ShiYu.Split('#')[3].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.YinShi_FangShi))
                {
                    chkFangShi1.Checked = child.SheHuiPingGuC.YinShi_FangShi.Split('#')[0].Equals("1");
                    chkFangShi2.Checked = child.SheHuiPingGuC.YinShi_FangShi.Split('#')[1].Equals("1");
                    chkFangShi3.Checked = child.SheHuiPingGuC.YinShi_FangShi.Split('#')[2].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.YinShi_LeiXing))
                {
                    checkLeiXing1.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[0].Equals("1");
                    checkLeiXing2.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[1].Equals("1");
                    checkLeiXing3.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[2].Equals("1");
                    checkLeiXing4.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[3].Equals("1");
                    checkLeiXing5.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[4].Equals("1");
                    checkLeiXing6.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[5].Equals("1");
                    checkLeiXing7.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[6].Equals("1");
                    checkLeiXing8.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[7].Equals("1");
                    checkLeiXing9.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[8].Equals("1");
                    if (child.SheHuiPingGuC.YinShi_LeiXing.Split('#').Length >= 10)
                        checkLeiXing10.Checked = child.SheHuiPingGuC.YinShi_LeiXing.Split('#')[9].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.HuoDong))
                {
                    chkHuoDong1.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[0].Equals("1");
                    chkHuoDong2.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[1].Equals("1");
                    chkHuoDong3.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[2].Equals("1");
                    chkHuoDong4.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[3].Equals("1");
                    chkHuoDong5.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[4].Equals("1");
                    chkHuoDong6.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[5].Equals("1");
                    chkHuoDong7.Checked = child.SheHuiPingGuC.HuoDong.Split('#')[6].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.ShuiMian))
                {
                    checShuiMian1.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[0].Equals("1");
                    checShuiMian2.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[1].Equals("1");
                    checShuiMian3.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[2].Equals("1");
                    checShuiMian4.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[3].Equals("1");
                    checShuiMian5.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[4].Equals("1");
                    checShuiMian6.Checked = child.SheHuiPingGuC.ShuiMian.Split('#')[5].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.ZiLi))
                {
                    checkZiLi1.Checked = child.SheHuiPingGuC.ZiLi.Split('#')[0].Equals("1");
                    checkZiLi2.Checked = child.SheHuiPingGuC.ZiLi.Split('#')[1].Equals("1");
                    checkZiLi3.Checked = child.SheHuiPingGuC.ZiLi.Split('#')[2].Equals("1");
                    checkZiLi4.Checked = child.SheHuiPingGuC.ZiLi.Split('#')[3].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.PaiBian))
                {
                    checPaiBian1.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[0].Equals("1");
                    checPaiBian2.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[1].Equals("1");
                    checPaiBian3.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[2].Equals("1");
                    checPaiBian4.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[3].Equals("1");
                    checPaiBian5.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[4].Equals("1");
                    checPaiBian6.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[5].Equals("1");
                    checPaiBian7.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[6].Equals("1");
                    checPaiBian8.Checked = child.SheHuiPingGuC.PaiBian.Split('#')[7].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.PaiNiao))
                {
                    checkPaiNiao1.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[0].Equals("1");
                    checkPaiNiao2.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[1].Equals("1");
                    checkPaiNiao3.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[2].Equals("1");
                    checkPaiNiao4.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[3].Equals("1");
                    checkPaiNiao5.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[4].Equals("1");
                    checkPaiNiao6.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[5].Equals("1");
                    checkPaiNiao7.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[6].Equals("1");
                    checkPaiNiao8.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[7].Equals("1");
                    if (child.SheHuiPingGuC.PaiNiao.Split('#').Length >= 9)
                        checkPaiNiao9.Checked = child.SheHuiPingGuC.PaiNiao.Split('#')[8].Equals("1");
                }

                txtPaiNiaoVal.EditValue = child.SheHuiPingGuC.PaiNiao_Text;
                txtPaiNiaoVal.Visible = checkPaiNiao9.Checked;

                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.DaoGuan))
                {
                    checkDaoGuan1.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[0].Equals("1");
                    checkDaoGuan2.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[1].Equals("1");
                    checkDaoGuan3.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[2].Equals("1");
                    checkDaoGuan4.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[3].Equals("1");
                    checkDaoGuan5.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[4].Equals("1");
                    checkDaoGuan6.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[5].Equals("1");
                    checkDaoGuan7.Checked = child.SheHuiPingGuC.DaoGuan.Split('#')[6].Equals("1");
                }
                checkDaoGuan8.EditValue = child.SheHuiPingGuC.DaoGuan_Text;
                checkDaoGuan8.Visible = checkDaoGuan7.Checked;

                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.ShengHuoHuanJing))
                {
                    chkShenghuohj1.Checked = child.SheHuiPingGuC.ShengHuoHuanJing.Split('#')[0].Equals("1");
                    chkShenghuohj2.Checked = child.SheHuiPingGuC.ShengHuoHuanJing.Split('#')[1].Equals("1");
                    chkShenghuohj3.Checked = child.SheHuiPingGuC.ShengHuoHuanJing.Split('#')[2].Equals("1");
                    chkShenghuohj4.Checked = child.SheHuiPingGuC.ShengHuoHuanJing.Split('#')[3].Equals("1");
                    chkShenghuohj5.Checked = child.SheHuiPingGuC.ShengHuoHuanJing.Split('#')[4].Equals("1");
                }
                txtShenghuohj.EditValue = child.SheHuiPingGuC.ShengHuoHuanJing_Text;
                txtShenghuohj.Visible = chkShenghuohj5.Checked;
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.FeiYongLaiYuan))
                {
                    chkFeiyonglaiy1.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[0].Equals("1");
                    chkFeiyonglaiy2.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[1].Equals("1");
                    chkFeiyonglaiy3.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[2].Equals("1");
                    chkFeiyonglaiy4.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[3].Equals("1");
                    chkFeiyonglaiy5.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[4].Equals("1");
                    chkFeiyonglaiy6.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[5].Equals("1");
                    chkFeiyonglaiy7.Checked = child.SheHuiPingGuC.FeiYongLaiYuan.Split('#')[6].Equals("1");
                }
                txtFeiYongLaiy.EditValue = child.SheHuiPingGuC.FeiYongLaiYuan_Text;
                txtFeiYongLaiy.Visible = chkFeiyonglaiy7.Checked;
                if (!string.IsNullOrEmpty(child.SheHuiPingGuC.HuanErHuoJiaZhangDuiJiangYaoJieShouDeYiLiaoFuWuShiFouYouJingJiDeYouLv))
                {
                    chkJingjiYouLv1.Checked = child.SheHuiPingGuC.HuanErHuoJiaZhangDuiJiangYaoJieShouDeYiLiaoFuWuShiFouYouJingJiDeYouLv.Split('#')[0].Equals("1");
                    chkJingjiYouLv2.Checked = child.SheHuiPingGuC.HuanErHuoJiaZhangDuiJiangYaoJieShouDeYiLiaoFuWuShiFouYouJingJiDeYouLv.Split('#')[1].Equals("1");
                }
                //getFRA();
                //getPRA();
                txtDieDaoFengXianPingGuFenShu.Text = child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGuFenShu;
                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGu))
                {
                    chkDieDaoFengXianPingGuDiFengXian.Checked = child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGu.Split('#')[0].Equals("1");
                    chkDieDaoFengXianPingGuGaoFengXian.Checked = child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGu.Split('#')[1].Equals("1");
                }

                txtYaChuanFengXianPingGuFenShu.Text = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGuFenShu;
                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu))
                {
                    chkYaChuanFengXianPingGuFenShu_WuFengXian.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu.Split('#')[0].Equals("1");
                    chkYaChuanFengXianPingGuFenShu_DiWei.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu.Split('#')[1].Equals("1");
                    chkYaChuanFengXianPingGuFenShu_ZhongWei.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu.Split('#')[2].Equals("1");
                    chkYaChuanFengXianPingGuFenShu_GaoWei.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu.Split('#')[3].Equals("1");
                    chkYaChuanFengXianPingGuFenShu_JiGaoWei.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu.Split('#')[4].Equals("1");
                }
                //风险数据结束

                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong))
                {
                    checkYuGangJieZhong_AnJiHua.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong.Split('#')[0].Equals("1");
                    checkYuGangJieZhong_WeiAnJiHua.Checked = child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong.Split('#')[1].Equals("1");
                }
                checkYuGangJieZhong_Text.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong_Text;
                if (checkYuGangJieZhong_WeiAnJiHua.Checked) checkYuGangJieZhong_Text.Visible = true;
                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi))
                {
                    checkGuoMinShi_WeiFaXian.Checked = child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi.Split('#')[0].Equals("1");
                    checkGuoMinShi_YaoWu.Checked = child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi.Split('#')[1].Equals("1");
                    checkGuoMinShi_ShiWu.Checked = child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi.Split('#')[2].Equals("1");
                    checkGuoMinShi_QiTa.Checked = child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi.Split('#')[3].Equals("1");
                }

                checkGuoMinShi_YaoWu_Text.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_YaoWu_Text;
                if (checkGuoMinShi_YaoWu.Checked) checkGuoMinShi_YaoWu_Text.Visible = true;
                checkGuoMinShi_ShiWu_Text.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_ShiWu_Text;
                if (checkGuoMinShi_ShiWu.Checked) checkGuoMinShi_ShiWu_Text.Visible = true;
                checkGuoMinShi_QiTa_Text.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_QiTa_Text;
                if (checkGuoMinShi_QiTa.Checked) checkGuoMinShi_QiTa_Text.Visible = true;
                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi))
                {
                    checkJiWanShi.Checked = child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi.Split('#')[0].Equals("1");
                    checkGaoXuYa.Checked = child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi.Split('#')[1].Equals("1");
                    checkTangNiaoBing.Checked = child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi.Split('#')[2].Equals("1");
                    checkQiTa.Checked = child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi.Split('#')[3].Equals("1");
                }

                checkQiTa_Text.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi_Text;
                if (checkQiTa.Checked) checkQiTa_Text.Visible = true;


                txtRuYuan_HuShiQianMing.EditValue = child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing;
                if (!string.IsNullOrEmpty(child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing_ShiJian))
                    dateShiJian.DateTime = Convert.ToDateTime(child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing_ShiJian);

                if (!string.IsNullOrEmpty(child.ChuYuanPingGuC.ChuYuanRiQi))
                    txtOUT_DATE.DateTime = Convert.ToDateTime(child.ChuYuanPingGuC.ChuYuanRiQi);

                if (txtOUT_DATE.DateTime == null) txtOUT_DATE.Text = string.Empty;
                if (txtOUT_DATE.Text.StartsWith("0")) txtOUT_DATE.Text = string.Empty;

                txtChuYuanZhenDuan.EditValue = child.ChuYuanPingGuC.ChuYuanZhenDuan;
                if (!string.IsNullOrEmpty(child.ChuYuanPingGuC.ZiLiNengLi))
                {
                    chkZiLiNengLi_WuXuYiLai.Checked = child.ChuYuanPingGuC.ZiLiNengLi.Split('#')[0].Equals("1");
                    chkZiLiNengLi_QingDuYiLai.Checked = child.ChuYuanPingGuC.ZiLiNengLi.Split('#')[1].Equals("1");
                    chkZiLiNengLi_ZhongDuYiLai.Checked = child.ChuYuanPingGuC.ZiLiNengLi.Split('#')[2].Equals("1");
                    chkZiLiNengLi_ZDYL.Checked = child.ChuYuanPingGuC.ZiLiNengLi.Split('#')[3].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.ChuYuanPingGuC.ChuYuanHouQuXiang))
                {
                    chkChuYuanHouQuXiang_HuiJia.Checked = child.ChuYuanPingGuC.ChuYuanHouQuXiang.Split('#')[0].Equals("1");
                    chkChuYuanHouQuXiang_KangFuLiaoYangYuan.Checked = child.ChuYuanPingGuC.ChuYuanHouQuXiang.Split('#')[1].Equals("1");
                    chkChuYuanHouQuXiang_ErTongFuLiYuan.Checked = child.ChuYuanPingGuC.ChuYuanHouQuXiang.Split('#')[2].Equals("1");
                    chkChuYuanHouQuXiang_QiTa.Checked = child.ChuYuanPingGuC.ChuYuanHouQuXiang.Split('#')[3].Equals("1");
                }
                if (!string.IsNullOrEmpty(child.ChuYuanPingGuC.JuJiaTiaoJian))
                {
                    checkJuZhuTiaoJian_FuMu.Checked = child.ChuYuanPingGuC.JuJiaTiaoJian.Split('#')[0].Equals("1");
                    checkJuZhuTiaoJian_WaiZuFuMu.Checked = child.ChuYuanPingGuC.JuJiaTiaoJian.Split('#')[1].Equals("1");
                    checkJuZhuTiaoJian_BaoMu.Checked = child.ChuYuanPingGuC.JuJiaTiaoJian.Split('#')[2].Equals("1");
                    checkJuZhuTiaoJian_BaoYuYuan.Checked = child.ChuYuanPingGuC.JuJiaTiaoJian.Split('#')[3].Equals("1");
                    checkJuZhuTiaoJian_QiTaRenYuan.Checked = child.ChuYuanPingGuC.JuJiaTiaoJian.Split('#')[4].Equals("1");
                }
                txtChuYuanHou_HuShiQianMing.EditValue = child.ChuYuanPingGuC.ChuYuanHuShiQianMing;
            }
            else if (ret.Code == 2)
            {
                this.Id = string.Empty;
                return;
            }
            else
            {
                MessageBox.Show(ret.M);
            }
        }

        #region 查询
        private void btn_Query_Click(object sender, EventArgs e)
        {
            BindInfo(this.Id);
        }
        #endregion

        #region 保存
        private void btn_Preservation_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(dateShiJian.Text))
                dateShiJian.DateTime = DateTime.Now;

            Child child = new Child();
            child.FormId = (int)FormType.Childs;
            child.FormName = EnumHelper.GetDescription(FormType.Childs);

            child.JiBenXinXiC.XingMing = txtName.Text.ToString();
            child.JiBenXinXiC.XingBie = ddlSex.Text.ToString();
            child.JiBenXinXiC.NianLing = txtAge.Text.ToString();
            child.JiBenXinXiC.BingQu = txtArea.Text.ToString();
            child.JiBenXinXiC.KeShi = txtDepartment.Text.ToString();
            child.JiBenXinXiC.ChuangHao = txtBedNo.Text.ToString();
            child.JiBenXinXiC.BingAnHao = txtPatientId.Text.ToString();
            child.JiBenXinXiC.RuYuanShiJian = txtInDate.Text.ToString();
            if (string.IsNullOrEmpty(child.JiBenXinXiC.RuYuanShiJian))
                child.JiBenXinXiC.RuYuanShiJian = PatientInfo.IN_DEPARTMENT_DATE.ToString("yyyy-MM-dd HH:mm:ss");
            child.JiBenXinXiC.RuYuanFangShi = ddlMode.Text.ToString();
            child.JiBenXinXiC.RuYuanZhenDuan = txtDiagnose.Text.ToString();
            child.JiBenXinXiC.MinZu = ddlNationals.Text.ToString();
            child.JiBenXinXiC.JiGuan = txtNativePlace.Text.ToString();
            child.JiBenXinXiC.LianXiRen = txtLinkman.Text.ToString();
            child.JiBenXinXiC.YuHuanZheGuanXi = ddlPATIENT_RELATION.Text.ToString();
            child.JiBenXinXiC.LianXiDianHua = txtPhone.Text.ToString();
            child.JiBenXinXiC.T = txtTEMPERATURE.Text.ToString();
            child.JiBenXinXiC.P = txtPULSE.Text.ToString();
            child.JiBenXinXiC.R = txtBREATHING.Text.ToString();
            child.JiBenXinXiC.BP = txtBLOOD_PRESSURE1.Text.Trim() + "/" + txtBLOOD_PRESSURE2.Text.ToString();
            child.JiBenXinXiC.BP1 = txtBLOOD_PRESSURE1.Text.Trim();
            child.JiBenXinXiC.BP2 = txtBLOOD_PRESSURE2.Text.Trim();

            child.JiBenXinXiC.SPO = txtSPO.Text.ToString();
            child.JiBenXinXiC.ShenGao = textHight.Text.ToString();
            child.JiBenXinXiC.TiZhong = txtWEIGHT.Text.ToString();

            child.TiZhengXinXiC.ShenZhi = (checShenZhi1.Checked ? 1 : 0) + "#" + (checShenZhi2.Checked ? 1 : 0) + "#" + (checShenZhi3.Checked ? 1 : 0)
                + "#" + (checShenZhi4.Checked ? 1 : 0) + "#" + (checShenZhi5.Checked ? 1 : 0) + "#" + (checShenZhi6.Checked ? 1 : 0) + "#" + (checShenZhi7.Checked ? 1 : 0);
            child.TiZhengXinXiC.ShenZhiText = checShenZhi8.Text.ToString();
            child.TiZhengXinXiC.JingShen = (checJingShen1.Checked ? 1 : 0) + "#" + (checJingShen2.Checked ? 1 : 0) + "#" + (checJingShen3.Checked ? 1 : 0);

            child.TiZhengXinXiC.KouQiang = (checkKouQiang1.Checked ? 1 : 0) + "#" + (checkKouQiang2.Checked ? 1 : 0) + "#" + (checkKouQiang3.Checked ? 1 : 0) + "#" + (checkKouQiang4.Checked ? 1 : 0);

            child.TiZhengXinXiC.KouQiangText = checkKouQiang5.Text.ToString();

            child.TiZhengXinXiC.KouChun = (checKouChun1.Checked ? 1 : 0) + "#" + (checKouChun2.Checked ? 1 : 0) + "#" + (checKouChun3.Checked ? 1 : 0) + "#" + (checKouChun4.Checked ? 1 : 0) + "#" +
                (checKouChun5.Checked ? 1 : 0) + "#" + (checKouChun6.Checked ? 1 : 0);

            child.TiZhengXinXiC.KouChunText = checKouChun7.Text.ToString();

            child.TiZhengXinXiC.PiFu = (checkPiFu1.Checked ? 1 : 0) + "#" + (checkPiFu2.Checked ? 1 : 0) + "#" + (checkPiFu3.Checked ? 1 : 0) + "#" + (checkPiFu4.Checked ? 1 : 0)
                + "#" + (checkPiFu5.Checked ? 1 : 0) + "#" + (checkPiFu6.Checked ? 1 : 0) + "#" + (checkPiFu7.Checked ? 1 : 0) + "#" + (checkPiFu8.Checked ? 1 : 0)
                + "#" + (checkPiFu9.Checked ? 1 : 0) + "#" + (checkPiFu10.Checked ? 1 : 0) + "#" + (checkPiFu11.Checked ? 1 : 0) + "#" + (checkPiFu12.Checked ? 1 : 0);

            child.TiZhengXinXiC.PiFuText = checkPiFu13.Text.ToString();

            child.SheHuiPingGuC.YinShi_ShiYu = (chkShiYu1.Checked ? 1 : 0) + "#" + (chkShiYu2.Checked ? 1 : 0) + "#" + (chkShiYu3.Checked ? 1 : 0) + "#" + (chkShiYu4.Checked ? 1 : 0);

            child.SheHuiPingGuC.YinShi_FangShi = (chkFangShi1.Checked ? 1 : 0) + "#" + (chkFangShi2.Checked ? 1 : 0) + "#" + (chkFangShi3.Checked ? 1 : 0);

            child.SheHuiPingGuC.YinShi_LeiXing = (checkLeiXing1.Checked ? 1 : 0) + "#" + (checkLeiXing2.Checked ? 1 : 0) + "#" + (checkLeiXing3.Checked ? 1 : 0) + "#" + (checkLeiXing4.Checked ? 1 : 0)
                + "#" + (checkLeiXing5.Checked ? 1 : 0) + "#" + (checkLeiXing6.Checked ? 1 : 0) + "#" + (checkLeiXing7.Checked ? 1 : 0) + "#" + (checkLeiXing8.Checked ? 1 : 0) + "#" + (checkLeiXing9.Checked ? 1 : 0)
                + "#" + (checkLeiXing10.Checked ? 1 : 0);

            child.SheHuiPingGuC.HuoDong = (chkHuoDong1.Checked ? 1 : 0) + "#" + (chkHuoDong2.Checked ? 1 : 0) + "#" + (chkHuoDong3.Checked ? 1 : 0) + "#" + (chkHuoDong4.Checked ? 1 : 0)
                + "#" + (chkHuoDong5.Checked ? 1 : 0) + "#" + (chkHuoDong6.Checked ? 1 : 0) + "#" + (chkHuoDong7.Checked ? 1 : 0);

            child.SheHuiPingGuC.ShuiMian = (checShuiMian1.Checked ? 1 : 0) + "#" + (checShuiMian2.Checked ? 1 : 0) + "#" + (checShuiMian3.Checked ? 1 : 0) + "#" + (checShuiMian4.Checked ? 1 : 0) + "#" +
                (checShuiMian5.Checked ? 1 : 0) + "#" + (checShuiMian6.Checked ? 1 : 0);

            child.SheHuiPingGuC.ZiLi = (checkZiLi1.Checked ? 1 : 0) + "#" + (checkZiLi2.Checked ? 1 : 0) + "#" + (checkZiLi3.Checked ? 1 : 0) + "#" + (checkZiLi4.Checked ? 1 : 0);

            child.SheHuiPingGuC.PaiBian = (checPaiBian1.Checked ? 1 : 0) + "#" + (checPaiBian2.Checked ? 1 : 0) + "#" + (checPaiBian3.Checked ? 1 : 0) + "#" + (checPaiBian4.Checked ? 1 : 0) + "#" +
                (checPaiBian5.Checked ? 1 : 0) + "#" + (checPaiBian6.Checked ? 1 : 0) + "#" + (checPaiBian7.Checked ? 1 : 0) + "#" + (checPaiBian8.Checked ? 1 : 0);

            child.SheHuiPingGuC.PaiNiao = (checkPaiNiao1.Checked ? 1 : 0) + "#" + (checkPaiNiao2.Checked ? 1 : 0) + "#" + (checkPaiNiao3.Checked ? 1 : 0) + "#" + (checkPaiNiao4.Checked ? 1 : 0)
                + "#" + (checkPaiNiao5.Checked ? 1 : 0) + "#" + (checkPaiNiao6.Checked ? 1 : 0) + "#" + (checkPaiNiao7.Checked ? 1 : 0) + "#" + (checkPaiNiao8.Checked ? 1 : 0) + "#" + (checkPaiNiao9.Checked ? 1 : 0);

            child.SheHuiPingGuC.PaiNiao_Text = txtPaiNiaoVal.Text;

            child.SheHuiPingGuC.DaoGuan = (checkDaoGuan1.Checked ? 1 : 0) + "#" + (checkDaoGuan2.Checked ? 1 : 0) + "#" + (checkDaoGuan3.Checked ? 1 : 0) + "#" + (checkDaoGuan4.Checked ? 1 : 0)
                + "#" + (checkDaoGuan5.Checked ? 1 : 0) + "#" + (checkDaoGuan6.Checked ? 1 : 0) + "#" + (checkDaoGuan7.Checked ? 1 : 0);

            child.SheHuiPingGuC.DaoGuan_Text = checkDaoGuan8.Text.ToString();

            child.SheHuiPingGuC.ShengHuoHuanJing = (chkShenghuohj1.Checked ? 1 : 0) + "#" + (chkShenghuohj2.Checked ? 1 : 0) + "#" + (chkShenghuohj3.Checked ? 1 : 0)
                + "#" + (chkShenghuohj4.Checked ? 1 : 0) + "#" + (chkShenghuohj5.Checked ? 1 : 0);

            child.SheHuiPingGuC.ShengHuoHuanJing_Text = txtShenghuohj.Text.ToString();

            child.SheHuiPingGuC.FeiYongLaiYuan = (chkFeiyonglaiy1.Checked ? 1 : 0) + "#" + (chkFeiyonglaiy2.Checked ? 1 : 0) + "#" + (chkFeiyonglaiy3.Checked ? 1 : 0)
                + "#" + (chkFeiyonglaiy4.Checked ? 1 : 0) + "#" + (chkFeiyonglaiy5.Checked ? 1 : 0) + "#" + (chkFeiyonglaiy6.Checked ? 1 : 0) + "#" + (chkFeiyonglaiy7.Checked ? 1 : 0);

            child.SheHuiPingGuC.FeiYongLaiYuan_Text = txtFeiYongLaiy.Text.ToString();

            child.SheHuiPingGuC.HuanErHuoJiaZhangDuiJiangYaoJieShouDeYiLiaoFuWuShiFouYouJingJiDeYouLv = (chkJingjiYouLv1.Checked ? 1 : 0) + "#" + (chkJingjiYouLv2.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGuFenShu = txtDieDaoFengXianPingGuFenShu.Text.ToString();
            child.DieDaoYaChuangADLFengXianPingGuC.DieDaoPingGu = (chkDieDaoFengXianPingGuDiFengXian.Checked ? 1 : 0) + "#" + (chkDieDaoFengXianPingGuGaoFengXian.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGuFenShu = txtYaChuanFengXianPingGuFenShu.Text.ToString();
            child.DieDaoYaChuangADLFengXianPingGuC.YaChuangPingGu = (chkYaChuanFengXianPingGuFenShu_WuFengXian.Checked ? 1 : 0) + "#" + (chkYaChuanFengXianPingGuFenShu_DiWei.Checked ? 1 : 0)
                + "#" + (chkYaChuanFengXianPingGuFenShu_ZhongWei.Checked ? 1 : 0) + "#" + (chkYaChuanFengXianPingGuFenShu_GaoWei.Checked ? 1 : 0) + "#" + (chkYaChuanFengXianPingGuFenShu_JiGaoWei.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong = (checkYuGangJieZhong_AnJiHua.Checked ? 1 : 0) + "#" +
                (checkYuGangJieZhong_WeiAnJiHua.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.YuFangJieZhong_Text = checkYuGangJieZhong_Text.Text.ToString();

            child.DieDaoYaChuangADLFengXianPingGuC.GuoMingShi = (checkGuoMinShi_WeiFaXian.Checked ? 1 : 0) + "#" +
                (checkGuoMinShi_YaoWu.Checked ? 1 : 0) + "#" + (checkGuoMinShi_ShiWu.Checked ? 1 : 0) + "#" + (checkGuoMinShi_QiTa.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_YaoWu_Text = checkGuoMinShi_YaoWu_Text.Text.ToString();

            child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_ShiWu_Text = checkGuoMinShi_ShiWu_Text.Text.ToString();

            child.DieDaoYaChuangADLFengXianPingGuC.GuoMinShi_QiTa_Text = checkGuoMinShi_QiTa_Text.Text.ToString();

            child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi = (checkJiWanShi.Checked ? 1 : 0) + "#" + (checkGaoXuYa.Checked ? 1 : 0) + "#" +
                (checkTangNiaoBing.Checked ? 1 : 0) + "#" + (checkQiTa.Checked ? 1 : 0);

            child.DieDaoYaChuangADLFengXianPingGuC.JiWangShi_Text = checkQiTa_Text.Text.ToString();

            child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing = txtRuYuan_HuShiQianMing.Text;
            if (txtRuYuan_HuShiQianMing_ID && !string.IsNullOrEmpty(txtRuYuan_HuShiQianMing.Text) && txtRuYuan_HuShiQianMing.Text.Equals(LoginUser.UserName))
                child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing_ID = this.LoginUser.UserId;

            child.DieDaoYaChuangADLFengXianPingGuC.RuYuanHuShiQianMing_ShiJian = dateShiJian.DateTime.ToString("yyyy-MM-dd");//日期

            child.ChuYuanPingGuC.ChuYuanRiQi = txtOUT_DATE.DateTime.ToString("yyyy-MM-dd HH:mm:ss");
            child.ChuYuanPingGuC.ChuYuanZhenDuan = txtChuYuanZhenDuan.Text.ToString();

            child.ChuYuanPingGuC.ZiLiNengLi = (chkZiLiNengLi_WuXuYiLai.Checked ? 1 : 0) + "#" + (chkZiLiNengLi_QingDuYiLai.Checked ? 1 : 0) + "#" +
                (chkZiLiNengLi_ZhongDuYiLai.Checked ? 1 : 0) + "#" + (chkZiLiNengLi_ZDYL.Checked ? 1 : 0);

            child.ChuYuanPingGuC.ChuYuanHouQuXiang = (chkChuYuanHouQuXiang_HuiJia.Checked ? 1 : 0) + "#" + (chkChuYuanHouQuXiang_KangFuLiaoYangYuan.Checked ? 1 : 0)
                + "#" + (chkChuYuanHouQuXiang_ErTongFuLiYuan.Checked ? 1 : 0) + "#" + (chkChuYuanHouQuXiang_QiTa.Checked ? 1 : 0);

            child.ChuYuanPingGuC.JuJiaTiaoJian = (checkJuZhuTiaoJian_FuMu.Checked ? 1 : 0) + "#" + (checkJuZhuTiaoJian_WaiZuFuMu.Checked ? 1 : 0) + "#" + (checkJuZhuTiaoJian_BaoMu.Checked ? 1 : 0) + "#" +
                (checkJuZhuTiaoJian_BaoYuYuan.Checked ? 1 : 0) + "#" + (checkJuZhuTiaoJian_QiTaRenYuan.Checked ? 1 : 0);

            child.ChuYuanPingGuC.ChuYuanHuShiQianMing = txtChuYuanHou_HuShiQianMing.Text.ToString();
            if (txtChuYuanHou_HuShiQianMing_ID && !string.IsNullOrEmpty(txtChuYuanHou_HuShiQianMing.Text) && txtChuYuanHou_HuShiQianMing.Text.Equals(LoginUser.UserName))
                child.ChuYuanPingGuC.ChuYuanHuShiQianMing_ID = this.LoginUser.UserId;

            record.NursingFormData = XmlUtil.ObjectToXML(child, Encoding.UTF8);
            record.FormId = child.FormId;//表单ID
            record.FormName = child.FormName;//表单NAME
            record.PatientId = PatientInfo.PATIENT_ID;//住院号
            record.VisitId = PatientInfo.VISIT_ID;//住院次数
            record.PatientName = PatientInfo.PATIENT_NAME;//患者名称
            record.BedNo = PatientInfo.BED_NO;//床号
            record.DepartmentId = PatientInfo.DEPARTMENT_ID;//科室号
            record.DepartmentName = PatientInfo.DEPARTMENT_NAME;//科室名称
            record.AreaId = PatientInfo.NURSE_CELL_CODE;//病区编号
            record.AreaName = PatientInfo.NURSE_CELL_NAME;//病区名称
            record.AssessmentDate = dateShiJian.DateTime;//日期       

            record.Id = Id == "" ? 0 : Convert.ToInt32(Id);
            var ret = formService.SetNursingFormRecord(Newtonsoft.Json.JsonConvert.SerializeObject(record));

            if (ret.Code == 1)
            {
                //电签开始
                if (Base.ESSwitch.Equals("on"))
                {
                    string extraInfo = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><root><sign_sys>{0}</sign_sys><title>{1}</title><patient_id>{2}</patient_id><patient_name>{3}</patient_name><emr_id>{4}</emr_id><emr_catalog>{5}</emr_catalog><his_id>{6}</his_id><event_no>{7}</event_no><visit_number>{8}</visit_number><dept_name>{9}</dept_name><prescribe_number>{10}</prescribe_number><prescribe_sub_number>{11}</prescribe_sub_number><prescribe_operation>医嘱操作（发送、校对、停止、作废）或门诊处方操作（发送）</prescribe_operation><radiotherapy_id>放疗号</radiotherapy_id><process_name>CT定位申请单审核</process_name><process_time>CT定位申请单审核时间</process_time><extend_value_1>备用扩展1</extend_value_1><extend_value_2>备用扩展2</extend_value_2><extend_value_3>备用扩展3</extend_value_3><extend_value_4>备用扩展4</extend_value_4><extend_value_5>备用扩展5</extend_value_5><extend_value_6>备用扩展6</extend_value_6><extend_value_7>备用扩展7</extend_value_7><extend_value_8>备用扩展8</extend_value_8><extend_value_9>备用扩展9</extend_value_9></root>";
                    extraInfo = string.Format(extraInfo, EnumHelper.GetDescription(FormType.Childs) + (record.Id > 0 ? "-更新" : "-新增"), EnumHelper.GetDescription(FormType.Childs), record.PatientId, record.PatientName, record.Id, record.FormId, "", record.PatientId, record.VisitId, LoginUser.DepartmentName, record.PatientId, record.PatientId);
                    ElectronicSignature es = new ElectronicSignature(LoginUser);
                    bool res = es.GetElectronicSignatureImage(es, record.NursingFormData, extraInfo, ((int)FormType.Childs).ToString(), EnumHelper.GetDescription(FormType.Childs), PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID);
                    if (!res) { MessageBox.Show("电子签名失败"); return; }
                }
                MessageBox.Show(record.Id == 0 ? "新增成功" : "更新成功");
                if (record.Id > 0) return;
                //新增成功后绑定数据
                this.Id = string.Empty;
                BindInfo(this.Id);
            }
            else
            {
                MessageBox.Show(ret.M);
            }
            this.DialogResult = DialogResult.OK;
        }
        #endregion

        #region 打印
        private void btn_Printing_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.Id))
            {
                MessageBox.Show("请先保存数据");
                return;
            }
            PrintHospitalizedChildren f = new PrintHospitalizedChildren(LoginUser, PatientInfo, Id);
            f.Show();
        }
        #endregion

        #region 跌倒风险和压疮数据获取
        private void btnFALL_RISK_ASSESSMENT_SCORE_Click(object sender, EventArgs e)
        {
            //跌倒风险评估
            getFRA();
        }
        //跌倒坠床风险评估单
        private void getFRA()
        {
            string fall_risk_assessment_score = string.Empty;//跌倒 来自于住院患儿跌倒表单
            var retFRA = formService.GetNursingFormRecord(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.FallFRA);
            if (retFRA.Code == 1 && retFRA.D != null)
            {
                List<NursingFormRecord> lsFRA = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(retFRA.D);
                lsFRA = lsFRA.OrderByDescending(a => a.AssessmentDate).ToList();//时间降序
                if (lsFRA.Count > 0)
                {
                    NursingFormRecord rdFra = lsFRA[lsFRA.Count - 1];//取最初的
                    Fallfar ps = XmlUtil.XMLToObject<Fallfar>(rdFra.NursingFormData, Encoding.UTF8);
                    if (ps != null)
                    {
                        fall_risk_assessment_score = ps.ZongDeFen + "";
                        txtDieDaoFengXianPingGuFenShu.Text = fall_risk_assessment_score;
                    }
                }
            }
            if (!string.IsNullOrEmpty(fall_risk_assessment_score))
            {
                txtDieDaoFengXianPingGuFenShu.Text = fall_risk_assessment_score;
                int fra_score = int.Parse(fall_risk_assessment_score);
                //先重置所有的复选框
                chkDieDaoFengXianPingGuDiFengXian.Checked = false;
                chkDieDaoFengXianPingGuGaoFengXian.Checked = false;
                //再根据值勾上
                if (fra_score < 15)
                {//低风险
                    chkDieDaoFengXianPingGuDiFengXian.Checked = true;
                }
                if (fra_score >= 15)
                {//高风险
                    chkDieDaoFengXianPingGuGaoFengXian.Checked = true;
                }
            }
        }

        private void btnPRESSURE_RISK_ASSESSMENT_SCORE_Click(object sender, EventArgs e)
        {
            //压疮风险评估
            getPRA();
        }
        //压疮风险评估记录单
        private void getPRA()
        {
            string pressure_risk_assessment_score = string.Empty;//压疮
            var retPRA = formService.GetNursingFormRecord(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID, (int)FormType.RiskSore);
            if (retPRA.Code == 1 && retPRA.D != null)
            {
                List<NursingFormRecord> lsPRA = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(retPRA.D);
                lsPRA = lsPRA.OrderByDescending(a => a.AssessmentDate).ToList();//时间降序
                if (lsPRA.Count > 0)
                {
                    NursingFormRecord rdFra = lsPRA[lsPRA.Count - 1];//取最旧的
                    RiskSore ps = XmlUtil.XMLToObject<RiskSore>(rdFra.NursingFormData, Encoding.UTF8);
                    if (ps != null)
                    {
                        pressure_risk_assessment_score = ps.ZongFen + "";
                        txtYaChuanFengXianPingGuFenShu.Text = pressure_risk_assessment_score;
                    }
                }
            }
            if (!string.IsNullOrEmpty(pressure_risk_assessment_score))
            {
                txtYaChuanFengXianPingGuFenShu.Text = pressure_risk_assessment_score;
                int prfa_score = int.Parse(pressure_risk_assessment_score);
                //先重置所有的复选框
                chkYaChuanFengXianPingGuFenShu_WuFengXian.Checked = false;
                chkYaChuanFengXianPingGuFenShu_DiWei.Checked = false;
                chkYaChuanFengXianPingGuFenShu_ZhongWei.Checked = false;
                chkYaChuanFengXianPingGuFenShu_GaoWei.Checked = false;
                chkYaChuanFengXianPingGuFenShu_JiGaoWei.Checked = false;
                //再根据值勾上
                if (prfa_score >= 19 && prfa_score <= 23)//无风险
                {
                    chkYaChuanFengXianPingGuFenShu_WuFengXian.Checked = true;
                }
                if (prfa_score >= 15 && prfa_score <= 18)//低危
                {
                    chkYaChuanFengXianPingGuFenShu_DiWei.Checked = true;
                }
                if (prfa_score >= 13 && prfa_score <= 14)//中危
                {
                    chkYaChuanFengXianPingGuFenShu_ZhongWei.Checked = true;
                }
                if (prfa_score >= 10 && prfa_score <= 12)//高危
                {
                    chkYaChuanFengXianPingGuFenShu_GaoWei.Checked = true;
                }
                if (prfa_score <= 9)//极高危
                {
                    chkYaChuanFengXianPingGuFenShu_JiGaoWei.Checked = true;
                }
            }
        }
        #endregion

        #region 签名事件
        bool txtRuYuan_HuShiQianMing_ID = false;
        private void ruyuanhushiqianming_Click(object sender, EventArgs e)
        {
            //入院签名
            if (!string.IsNullOrEmpty(txtRuYuan_HuShiQianMing.Text))
                return;

            txtRuYuan_HuShiQianMing.Text = LoginUser.UserName;
            txtRuYuan_HuShiQianMing_ID = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, txtRuYuan_HuShiQianMing, pictureBox1, txtRuYuan_HuShiQianMing.Location);
        }

        bool txtChuYuanHou_HuShiQianMing_ID = false;
        private void chuyuanhushiqianming_Click(object sender, EventArgs e)
        {
            //出院签名
            if (!string.IsNullOrEmpty(txtChuYuanHou_HuShiQianMing.Text))
                return;

            txtChuYuanHou_HuShiQianMing.Text = LoginUser.UserName;
            txtChuYuanHou_HuShiQianMing_ID = true;
            es.SearchElectronicSignatureImage(Base.ESSwitch, LoginUser, txtChuYuanHou_HuShiQianMing, pictureBox1, txtChuYuanHou_HuShiQianMing.Location);
        }
        #endregion

        #region 获取体征电话等信息事件
        private void BtnGetData_Click(object sender, EventArgs e)
        {
            GetTemperaAllData();
        }

        private void GetTemperaAllData()
        {
            if (this.PatientInfo == null) return;
            //导入体温相关
            TemperatureIn x = new TemperatureIn(PatientInfo.PATIENT_ID, PatientInfo.VISIT_ID.ToString());
            x.ShowDialog();
            if (x.DialogResult == DialogResult.Yes)
            {
                txtTEMPERATURE.Text = x.tiwen;
                txtPULSE.Text = x.maibo;
                txtBREATHING.Text = x.huxi;
                txtBLOOD_PRESSURE1.Text = x.xueya1;
                txtBLOOD_PRESSURE2.Text = x.xueya2;
            }
            if (string.IsNullOrEmpty(txtPhone.Text))
                txtPhone.EditValue = PatientInfo.PHONE;
        }
        #endregion
    }
}